from prance import ResolvingParser
import json

class CustomParser(ResolvingParser):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.seen_refs = set()

    def resolve_ref(self, ref):
        if ref in self.seen_refs:
            # If we've seen this ref before, mark it as recursive
            return {"recursive_ref": ref}
        self.seen_refs.add(ref)
        return super().resolve_ref(ref)


with open("test.yaml", 'r', encoding='utf') as f:
    your_yaml_string = f.read()

parser = CustomParser(spec_string=your_yaml_string)
parser.parse()

# 打印解析结果
print(json.dumps(parser.specification, indent=2))